package com.cat.dynamicPlanning;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/partition-equal-subset-sum/description/
 * @create 2025/9/1 18:11
 * @since JDK17
 */

public class Solution42 {
    public boolean canPartition(int[] nums) {
        int n = nums.length, sum = Arrays.stream(nums).sum(), target = sum / 2;
        if (sum % 2 == 1) {
            return false;
        }
        boolean[] dp = new boolean[target + 1];
        dp[0] = true;
        for (int i = 0; i < n; i++) {
            for (int j = target; j >= nums[i]; j--) {
                dp[j] = dp[j] || dp[j - nums[i]];
            }
        }

        return dp[target];
    }
}
